package com.example.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.dto.interview;
import org.apache.ibatis.annotations.*;

@Mapper
public interface InterviewMapper {

    //获取当前公司招聘信息
    @Select("select * from employer,position where employer.`PositionID`=position.`PositionID`")
    IPage<interview> AllList(Page<interview> interviewPage);

    //公司名称查询
    @Select("select *" +
            " from(select employer.Name,employer.Address,employer.ContactInfo,position.Responsibilities,position.Salary,position.PositionName from employer,position where employer.`PositionID`=position.`PositionID`) as eTable " +
            "where Name like concat('%', #{key}, '%')")
    IPage<interview> findByName(Page<interview> interviewPage,String key);

    //工作岗位查询
    @Select("select * " +
            "from(select employer.Name,employer.Address,employer.ContactInfo,position.Responsibilities,position.Salary,position.PositionName from employer,position where employer.`PositionID`=position.`PositionID`) as eTable " +
            "where PositionName like concat('%', #{key}, '%')")
    IPage<interview> findByPosition(Page<interview> interviewPage,String key);

    //插入position表
    @Insert("insert into `position`(PositionName,Salary,Responsibilities)"+"values(#{PositionName},#{Salary},#{Responsibilities})")
    void addPosition(interview i);

    //查询position表获取positionID
    @Select("select PositionID from position where PositionName=#{name} and Salary=#{Salary}")
    Integer getPositionID(String name,Double Salary);

    //插入employer表
    @Insert("insert into employer(PositionID,Name,ContactInfo,Address)"+"values(#{PositionID},#{Name},#{ContactInfo},#{Address})")
    void addEmployer(interview i);

    //删除招聘信息
    @Delete("delete from employer where Name=#{name} and PositionID=#{id}")
    void delete(String name, Integer id);

    //修改employer表
    @Update("update `employer` set ContactInfo=#{ContactInfo},Address=#{Address} where Name=#{name} and PositionID=#{PositionID}")
    void editEmploy(interview i);

    //修改position表
    @Update("update `position` set Responsibilities=#{Responsibilities} where PositionID=#{PositionID}")
    void editPosition(interview i);
}
